package com.jwaoo.mobile.view.explore.adapter;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.Drawable;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.dx.as.common.string.StringUtil;
import com.dx.as.ui.CircleImageView;
import com.jwaoo.mobile.R;
import com.jwaoo.mobile.view.explore.UserFragment;
import com.jwaoo.mobile.view.explore.bean.UserBean;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.List;
public class UserRecyclerViewAdapter extends RecyclerView.Adapter<UserRecyclerViewAdapter.ViewHolder> {

    private final List<UserBean> mValues;
    private final UserFragment.OnListFragmentInteractionListener mListener;
    private Bitmap bitmap;
    public UserRecyclerViewAdapter(List<UserBean> items, UserFragment.OnListFragmentInteractionListener listener) {
        mValues = items;
        mListener = listener;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.fragment_contacts, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(final ViewHolder holder, int position) {
        holder.mItem = mValues.get(position);
        holder.nickName.setText(mValues.get(position).getNickname());
        ImageLoader.getInstance().displayImage(mValues.get(position).getAvatar(),holder.img_avatar);
        holder.mView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (null != mListener) {
                    mListener.onListFragmentInteraction(holder.mItem);
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return mValues.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        public final View mView;
        public final TextView nickName;
        public CircleImageView img_avatar;
        public UserBean mItem;

        public ViewHolder(View view) {
            super(view);
            mView = view;
            nickName = view.findViewById(R.id.tv_nickname);
            img_avatar = view.findViewById(R.id.img_avatar);

        }

        @Override
        public String toString() {
            return super.toString() + " '" + nickName.getText() + "'";
        }
    }
}
